﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Bigeagle.Portable.BoardGames;
using Bigeagle.Portable.BoardGames.Go;
// “用户控件”项模板在 http://go.microsoft.com/fwlink/?LinkId=234236 上提供

namespace EagleGO
{
    /// <summary>
    /// 棋谱信息控件
    /// </summary>
    public sealed partial class KiFUInfoControl : UserControl
    {
        public static readonly DependencyProperty GameInfoProperty =
    DependencyProperty.Register("GameInfo", typeof(GoGameInfo), typeof(KiFUInfoControl)
    , new PropertyMetadata(new GoGameInfo(), new PropertyChangedCallback(OnGameInfoChanged)));

        public GoGameInfo GameInfo
        {
            get
            {
                return (GoGameInfo)GetValue(GameInfoProperty);
            }
            set
            {
                SetValue(GameInfoProperty, value);
            }
        }
        private static void OnGameInfoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            KiFUInfoControl control = (KiFUInfoControl)d;
            GoGameInfo gameInfo = e.NewValue as GoGameInfo;
            if (gameInfo != null)
            {
                control.tbBlackPlayer.Text = gameInfo.BlackPlayer.ToChineseString();
                control.tbWhitePlayer.Text = gameInfo.WhitePlayer.ToChineseString();
                control.tbResult.Text = gameInfo.Result != null ? gameInfo.Result.ChineseString : string.Empty;
                string title = string.IsNullOrEmpty(gameInfo.Name) ? gameInfo.Event : gameInfo.Name;
                title = string.IsNullOrEmpty(title) ?
                    string.Format("{0}-{1}"
                    , gameInfo.BlackPlayer.ToChineseString()
                    , gameInfo.WhitePlayer.ToChineseString())
                    : title;
                control.tbTitle.Text = title;
                control.tbDescription.Text = string.IsNullOrEmpty(gameInfo.Comment) ? "" : gameInfo.Comment;
            }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public KiFUInfoControl()
        {
            this.InitializeComponent();
        }//end method
    }//end class
}//end namespace
